package com.shameit.goodqrinfomanager.adapter;

import android.view.View;

import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProviders;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.shameit.goodqrinfomanager.bean.enity.OfflinListBean;
import com.shameit.goodqrinfomanager.databinding.OfflineLayoutItemBinding;
import com.shameit.goodqrinfomanager.ui.activity.offline.OfflineManagementViewModel;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

import me.goldze.mvvmhabit.utils.ToastUtils;

public class OfflineListAdapter extends BaseQuickAdapter<OfflinListBean, BaseDataBindingHolder<OfflineLayoutItemBinding>> {
    private List<OfflinListBean> list = new ArrayList<>();
    public OfflineListAdapter(int layoutResId) {
        super(layoutResId);
    }


    public void setData(List<OfflinListBean> data) {
        this.list = data;
    }

    @Override
    protected void convert(@NotNull BaseDataBindingHolder<OfflineLayoutItemBinding> offlineLayoutItemBindingBaseDataBindingHolder, OfflinListBean offlinListBean) {
        OfflineLayoutItemBinding binding = offlineLayoutItemBindingBaseDataBindingHolder.getDataBinding();
        if (binding != null) {
            binding.setData(offlinListBean);
            binding.setViewmodel(ViewModelProviders.of((FragmentActivity) getContext()).get(OfflineManagementViewModel.class));
        }
        binding.offlineItemCheckbox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("test:"+binding.offlineItemCheckbox.isChecked());
            }
        });
        binding.delBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtils.showShort("you clicked:"+getItemPosition(offlinListBean));
            }
        });


//        binding.uploadBtn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//            }
//        });

    }

}
